package org.sqp.base;

import javafx.geometry.Pos;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

public class PostBuilder {
    HttpPost post = null;
    List<NameValuePair> params = new ArrayList<NameValuePair>();

    public PostBuilder(HttpPost post) {
        this.post = post;
    }

    public PostBuilder(String url) {
        this.post = new HttpPost(url);
    }

    public PostBuilder addParam(String name,String value){
        params.add(new BasicNameValuePair(name,value));
        return this;
    }

    public PostBuilder addHeader(String name,String value){
        post.addHeader(name,value);
        return this;
    }

    public HttpPost build(){
        try {
            post.setEntity(new UrlEncodedFormEntity(params));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return post;
    }


}
